import React, { useState, useRef } from "react";
import { withRouter } from "react-router-dom";
import Table from "./components/Table";
import PageHead from "@/components/PageHead";
import CreateActiveForm from "./components/CreateActivityForm/index";

function Goods() {
  const [visible, setVisible] = useState(false);
  const [editInfo, setEditInfo] = useState();
  const childRef = useRef();
  const childForm = useRef();
  // 点击添加
  const handleClick = () => {
    setVisible(true);
    setTimeout(() => {
      childForm.current.clearData();
    }, 0);
  };
  // 关闭
  const onClose = () => {
    setVisible(false);
  };
  // 点击添加
  const submit = () => {
    childRef.current.fetchData();
  }
  // 修改
  const Edit = (record) => {
    setVisible(true);
    setEditInfo(record);
  }
  return (<div>
    {
      visible
        ? <CreateActiveForm refs={childForm} editInfo={editInfo} submit={submit} onClose={onClose} />
        : null
    }
    <PageHead title="试题管理" buttonText="添加试题" onClick={handleClick} />
    <Table Edit={Edit} refs={childRef} />
  </div>);
}

export default withRouter(Goods);
